package com.example.qa_back.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * @author 董帅
 * @date 2021/3/29 - 19:51
 */
public class HandlePython {
    public static ArrayList<Double> execPython(String str1, String[] str2) {
        ArrayList<Double> list = new ArrayList<>();
        try {
            String[] args1 = new String[str2.length+4];
            // 第一个参数是所使用的python，第二个参数是调用的python文件
            args1[0] = "python";
            args1[1] = "F:\\青海大学\\毕设\\代码\\QA_Python\\text_preprocess\\sentence_similarity.py";
            args1[2] = str1;
            args1[3] = String.valueOf(str2.length);
            System.arraycopy(str2, 0, args1, 4, args1.length - 4);
            Process pr=Runtime.getRuntime().exec(args1);
            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                list.add(Double.valueOf(line));
            }
            in.close();
            pr.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
